
public class MovieList {
	private MovieNode head; //link to head node
	private int numberOfItems; //number of items in LL
	
	//Constructor
	public MovieList() {
		head = null; //set head to null
		numberOfItems = 0; //initiate numberOfItems to 0
	}
	
	//Method Header
	public int size() {
		return numberOfItems;
	}
		
	//Method Header
	public boolean isEmpty() {
		return (numberOfItems == 0);
	}
	
	//Method Header
	public void addMovie(String[] movieData) {
		Movie newMovie = new Movie(movieData); //create movie obj
		MovieNode newMovieNode = new MovieNode(newMovie); //create node
		String newMovieTitle = getMovieTitle(newMovieNode); //get the title
		int newMovieID = getMovieID(newMovieNode); //store ID for repeated use
		
		MovieNode current = head; // keep track of where we are in the list
		MovieNode previous = null; // track last node
		
		if(current == null) { //if empty LL
			head = newMovieNode; //set new movie node as head
		}
		else {
			boolean done = false; //boolean for when to stop loop
			while(!done) {
				//check movie ID
				if(newMovieID != getMovieID(current)) {
					//store title of current movie
					String currentTitle = current.getData().getTitle();
					
					//store result of comparison
					int compToResult = newMovieTitle
											.compareToIgnoreCase(currentTitle);
					//if new title comes after current title
					if (compToResult > 0) {
						previous = current;
						current = current.getNext();
						if(current == null) { //if at the end
							previous.setNext(newMovieNode);
							done = true;
						}
					}
					else { //if new title comes before current title
						if(head == current) { //check if it goes before head
							newMovieNode.setNext(current);
							head = newMovieNode;
							done = true;
						}
						else { //just add it before current
							previous.setNext(newMovieNode);
							newMovieNode.setNext(current);
							done = true;
						}
					}
				}
				else { //if there was a matching ID
					System.out.println("Movie Add Error: Found movie with " +
							"matching ID..");
				}
			}
		}
		numberOfItems++; //we added an item so increment
	}
	
	//Method Header
	public void addShowing(String[] showingData) {
		MovieNode currMovie = head;
		
		Showing newShowing = new Showing(showingData); //create the obj
		
		int movieID = getMovieID(currMovie); //get the current movieID
		int showingID = Integer.parseInt(showingData[0]); //store showing ID
		
		int count = 0; //counter for loop
		//while inbounds and not matching ID's
		while(count < size() && movieID != showingID) {
			currMovie = currMovie.getNext();
			movieID = currMovie.getData().getID();
		}
		
		if(movieID == showingID) { //if match found
			ShowingList matchedShowList = currMovie.getShowList(); //get list
			matchedShowList.addShowing(newShowing);
		}
		else { //If no matching movies found
			System.out.println("Showing ID did not match any existing " +
					"movies..");
		}
	}
	
	//get movie ID
	public int getMovieID(MovieNode node) {
		return node.getData().getID();
	}
	
	//get movie title
	public String getMovieTitle(MovieNode node) {
		return node.getData().getTitle();
	}
	
	/*
	 * Method: searchMovies
	 * Purpose: Searches for movies matching the user's input. If the movie
	 * 			is found, the movie data and all of the showings are printed
	 * Parameters:
	 * 		String movieTitle:	The movie title to search for
	 * Returns: void
	 */
	
	public void searchMovies(String movieTitle) {
		
	}
	
	/*
	 * Method: setShowingTitles
	 * Purpose: Find the titles of the showings using the unique ID
	 * Parameters:
	 * Returns: void
	 */
	
	public void setShowingTitles() {
		
	}
	
	/*
	 * Method: printAll
	 * Purpose: print all movie and showing objs in readable format
	 * Parameters:
	 * Returns: void
	 */
	
	public void printAll () {
		int counter = size(); //store size of the movie list
		if(counter == 0) System.out.println("No movies found..");
		
		MovieNode current = head; //head of the list
		while(counter > 0) {
			System.out.println(getMovieTitle(current));
			current = current.getNext();
			counter--;
		}
	}
}
